﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class ItemPriceTest
    {
        [TestMethod]
        public void GeneralItemPriceTest()
        {
            ItemPrice itemPrice = new ItemPrice();

            Assert.IsNotNull(itemPrice.ID);
            Assert.AreEqual(1.0, itemPrice.Price);
            Assert.IsNull(itemPrice.Item);
            Assert.IsNull(itemPrice.Market);

            Item item = new Item();
            Market market = new Market();
            itemPrice.Item = item;
            itemPrice.Market = market;

            Assert.AreEqual("", itemPrice.Validate());
        }

        [TestMethod]
        public void ItemPriceItemPropertyChangedTest()
        {
            ItemPrice itemPrice = new ItemPrice();
            Assert.IsNull(itemPrice.Item);

            Item item = new Item();
            AssertHelper.PropertyChangedEvent(itemPrice, x => x.Item, () => itemPrice.Item = item);
            Assert.AreEqual(item, itemPrice.Item);
        }

        [TestMethod]
        public void ItemPriceMarketPropertyChangedTest()
        {
            ItemPrice itemPrice = new ItemPrice();
            Assert.IsNull(itemPrice.Market);

            Market market = new Market();
            AssertHelper.PropertyChangedEvent(itemPrice, x => x.Market, () => itemPrice.Market = market);
            Assert.AreEqual(market, itemPrice.Market);
        }

        [TestMethod]
        public void ItemPriceMarketValidationTest()
        {
            ItemPrice itemPrice = new ItemPrice();

            Assert.IsNull(itemPrice.Market);
            Assert.AreEqual(Resources.MarketMandatory, itemPrice.Validate("Market"));

            Market market = new Market();
            itemPrice.Market = market;
            Assert.AreEqual("", itemPrice.Validate("Market"));
        }

        [TestMethod]
        public void ItemPriceItemValidationTest()
        {
            ItemPrice itemPrice = new ItemPrice();

            Assert.IsNull(itemPrice.Item);
            Assert.AreEqual(Resources.ItemMandatory, itemPrice.Validate("Item"));

            Item item = new Item();
            itemPrice.Item = item;
            Assert.AreEqual("", itemPrice.Validate("Item"));
        }

        [TestMethod]
        public void ItemPricePriceValidationTest()
        {
            ItemPrice currencyExchange = new ItemPrice();

            Assert.AreEqual(1, currencyExchange.Price);

            currencyExchange.Price = 0.1;
            Assert.AreEqual("", currencyExchange.Validate("Price"));
            currencyExchange.Price = 0.0;
            Assert.AreEqual(Resources.PriceGreater, currencyExchange.Validate("Price"));
            currencyExchange.Price = -0.1;
            Assert.AreEqual(Resources.PriceGreater, currencyExchange.Validate("Price"));
        }
    }
}
